package com.tianzeculture.stagebao.activity.personal;

import android.widget.ListView;
import android.widget.TextView;

import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.activity.personal.adapter.FocusAdapter;
import com.tianzeculture.stagebao.base.BaseActivity;
import com.tianzeculture.stagebao.bean.FansBean;
import com.tianzeculture.stagebao.bean.ResultBean;
import com.tianzeculture.stagebao.net.CommonRestUsage;
import com.tianzeculture.stagebao.net.TagRestUsage;
import com.tianzeculture.stagebao.network.Request;
import com.tianzeculture.stagebao.network.enity.MSG;
import com.tianzeculture.stagebao.network.util.ToastUtil;
import com.tianzeculture.stagebao.util.StatusBarUtil;

import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/6/20 0020.
 * 关注
 */

public class MyFocusActivity extends BaseActivity implements FocusAdapter.AttentionListener {
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.lvJob)
    ListView lvJob;
    FocusAdapter focusAdapter;

    @Request
    TagRestUsage tagRestUsage = null;
    private int ToMyselfFollow = 101;
    private int saveAttentionId = 102;

    List<FansBean> list;
    private int cancelAttentionId = 1;

    @Override
    public void initUI() {
        super.initUI();
        StatusBarUtil.setWindowStatusBarColor(this, R.color.colorGray_F8);
        tvTitle.setText("关注");

        focusAdapter = new FocusAdapter(this, false);
        focusAdapter.setListener(this);
        lvJob.setAdapter(focusAdapter);
    }

    @Override
    protected void onResume() {
        super.onResume();
        tagRestUsage.getAttentionList(ToMyselfFollow);
    }

    @Override
    public void refreshUI(int taskId, MSG msg) {
        super.refreshUI(taskId, msg);
        if (taskId == ToMyselfFollow) {
            if (msg.getData()) {
                ResultBean resultBean = (ResultBean) msg.getObj();
                list = resultBean.getAttentionList();
                focusAdapter.setList(list);
            }
        }
        if (taskId == cancelAttentionId) {
            ToastUtil.showShort(this, msg.getMessage());
            if (msg.getData()) {
                tagRestUsage.getAttentionList(ToMyselfFollow);
            }
        }
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_select_job;
    }


    @Override
    public void doAttention(FansBean fansBean, int requestType) {
       if (requestType == 1) {
            tagRestUsage.cancleAttention(cancelAttentionId, fansBean.getId());
        }
    }
}
